using BasicScript.Component;
using Game.Core;
using Game.Main.Controller;
using Game.Manager;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Game.Main.View
{
	public class GameView : BaseView
	{
		private SceneController clr;

		private GameObject btnBack;

		private ButtonObject btnBackObj;

		private GameObject mask;

		private Transform lockMask;

		private Transform btnUnlock;

		private const float MIN_SCALE = 1f;

		private const float MAX_SCALE = 1.25f;

		public GameView(SceneController clr)
			: base("prefabs/ui/scene/gameview", Singleton<UIManager>.Instance.uiLayer)
		{
			viewName = "GameView";
			this.clr = clr;
		}

		protected override void OnLoaded()
		{
			btnBack = GetChild("BtnBack").gameObject;
			btnBackObj = btnBack.AddComponent<ButtonObject>();
			btnBackObj.InitParams(1.25f, 1.25f, 1f, 1f);
			UIEventSystem.Get(btnBack).AddEventListener(EventTriggerType.PointerDown, OnBtnBackDown);
			UIEventSystem.Get(btnBack).AddEventListener(EventTriggerType.PointerExit, OnBtnBackExit);
			UIEventSystem.Get(btnBack).AddEventListener(EventTriggerType.PointerUp, OnBtnBackUp);
			UIEventSystem.Get(btnBack).AddEventListener(EventTriggerType.PointerClick, OnBtnBackClick);
			mask = GetChild("Mask").gameObject;
			lockMask = GetChild("LockMask");
			btnUnlock = lockMask.Find("BtnUnlock");
			UIEventSystem.Get(btnUnlock.gameObject).AddEventListener(EventTriggerType.PointerDown, OnBtnUnlockDown);
			ZoomInOutObject zoomInOutObject = btnUnlock.gameObject.AddComponent<ZoomInOutObject>();
			zoomInOutObject.range = 0.1f;
			zoomInOutObject.speed = 0.5f;


        }

		public void SetLockMaskActive(bool val)
		{
			if (lockMask != null)
			{
				lockMask.gameObject.SetActive(false);
			}
		}

		private void OnBtnUnlockDown(BaseEventData evt)
		{
			clr.OCPurchaseView(true, true);
			Singleton<AudioManager>.Instance.PlaySound("sound_btn_1");
		}

		private void OnBtnBackDown(BaseEventData evt)
		{
			btnBackObj.ZoomIn();
			Singleton<AudioManager>.Instance.PlaySound("sound_btn_1");
		}

		private void OnBtnBackExit(BaseEventData evt)
		{
			btnBackObj.ZoomOut();
		}

		private void OnBtnBackUp(BaseEventData evt)
		{
			btnBackObj.ZoomOut();
		}

		private void OnBtnBackClick(BaseEventData evt)
		{
			clr.ChangeScene(SceneType.MAP_VIEW);
		}

		public void SetMaskActive(bool val)
		{
			mask.SetActive(val);
		}
	}
}
